package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.TimeTableConfig;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.TimeTableConfigMapper;
import com.zrwl.poscloud.xo.service.TimeTableConfigService;
import com.zrwl.poscloud.xo.vo.TimeTableConfigVO;

import javax.annotation.Resource;

/**
 * 管理员教师关联 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-05-08
 */
@Service
public class TimeTableConfigServiceImpl extends SuperServiceImpl<TimeTableConfigMapper,TimeTableConfig> implements TimeTableConfigService {

    @Autowired
    private TimeTableConfigService timeTableConfigService;

    @Resource
    private TimeTableConfigMapper timeTableConfigMapper;

    @Override
    public IPage<TimeTableConfigVO> getPageList(TimeTableConfigVO timeTableConfigVO){
       Page<TimeTableConfig> page = new Page<>();
       page.setCurrent(timeTableConfigVO.getCurrentPage());
       page.setSize(timeTableConfigVO.getPageSize());
       IPage<TimeTableConfigVO> pageList = timeTableConfigMapper.getTimeTableConfigPageList(page, timeTableConfigVO);
       List<TimeTableConfigVO> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<TimeTableConfig> getAllList(TimeTableConfigVO timeTableConfigVO){
        QueryWrapper<TimeTableConfig> queryWrapper = new QueryWrapper<>();
        if(timeTableConfigVO.getStatus() != 0){
            queryWrapper.eq(SQLConf.STATUS,timeTableConfigVO.getStatus());
        }
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.BEGIN_TIME);
        List<TimeTableConfig> list = timeTableConfigService.list(queryWrapper);
        return list;
}
    @Override
    public String add(TimeTableConfigVO timeTableConfigVO){
        TimeTableConfig entity = new TimeTableConfig();
        BeanUtils.copyProperties(timeTableConfigVO, entity, SysConf.STATUS);
        entity.insert();
        timeTableConfigVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(TimeTableConfigVO timeTableConfigVO){
        TimeTableConfig entity = timeTableConfigService.getById(timeTableConfigVO.getUid());
        BeanUtils.copyProperties(timeTableConfigVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(TimeTableConfigVO timeTableConfigVO){
        TimeTableConfig entity = timeTableConfigService.getById(timeTableConfigVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
